<?php
/*
 +----------------------------------------------------------------------
 + Title        : ApiService 控制器
 + Author       : Randy_chen
 + Version      : V1.0.0.1
 + Initial-Time : 2019/6/1 16:36
 + Last-time    : 2019/6/1 16:36+ 86187
 + Desc         : 第三方服务基础接口
 +----------------------------------------------------------------------
*/


namespace app\common\controller;


use think\App;
use think\Controller;

class ApiService extends Controller
{
    public function __construct(App $app = null)
    {
        parent::__construct($app);
    }

    //鉴权
    public function auth(){

    }

    //获取接口缓存
    public function getUserAuth( $channel_id ,$update = false){
        $key = 'api_user_auth_'.$channel_id;
        $list = cache($key);

        if($list === false || $update){
            $id = db('api_channel')->where('channel_id' , $channel_id)->where('status' ,1)->value('id');

            if (!$id) return false;
            //获取权限
            $privileges = db('api_user_auth')->where('ac_id' ,$id )->select();

            $list = [];
            foreach ( $privileges as $v){
                $pri = db('api_auth')->where('id' ,$v['auth_id'])->find();
                if(is_array($pri) ){
                    $list[$pri['id']] = $pri['url'];
                }
            }
            cache($key , $list);
        }

        return $list;
    }

}